
package com.tsh.core.log.logger;

import com.tsh.core.log.publisher.UsualLogPublisher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;

/**
 * 日志工具类
 *
 * @author Tsh
 */
@Slf4j
public class TshLogger implements InitializingBean {

	@Value("${spring.application.name}")
	private String serviceId;

	/**
	 * 普通信息日志
	 * @param type 日志类别
	 * @param id 业务id
	 * @param data 业务数据
	 */
	public void info(String type, String id, String data) {
		UsualLogPublisher.publishEvent("info", id, data);
	}

	/**
	 * 调式日志
	 * @param type 日志类别
	 * @param id 业务id
	 * @param data 业务数据
	 */
	public void debug(String type, String id, String data) {
		UsualLogPublisher.publishEvent("debug", id, data);
	}

	/**
	 * 警告日志
	 * @param type 日志类别
	 * @param id 业务id
	 * @param data 业务数据
	 */
	public void warn(String type, String id, String data) {
		UsualLogPublisher.publishEvent("warn", id, data);
	}

	/**
	 * 错误日志
	 * @param type 日志类别
	 * @param id 业务id
	 * @param data 业务数据
	 */
	public void error(String type, String id, String data) {
		UsualLogPublisher.publishEvent("error", id, data);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		log.info(serviceId + ": TshLogger init success!");
	}

}
